/*
 * This file is part of WebCL – JavaScript bindings for OpenCL
 * http://webcl.nokiaresearch.com/
 *
 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 *
 * Contact: Jari Nikara  ;jari.nikara@nokia.com;
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 *
 * The package is based on a published Khronos OpenCL 1.1 Specification,
 * see http://www.khronos.org/opencl/.
 *
 * OpenCL is a trademark of Apple Inc.
 */

/** \interface IWebCL
 * Main WebCL component interface.
 * This interface provides the primary access to WebCL functionality, providing
 * an API for retrieving a list of available platforms, context creation and
 * various utilities and constants.
 * This interface is intended to be made directly available for the JavaScript
 * context as a global object or via a constructor.
 */

#include "nsISupports.idl"
#include "nsISecurityCheckedComponent.idl"
#include "nsIVariant.idl"
#include "nsIArray.idl"

#include "WebCL_types.idl"

interface IWebCLContext;
interface IWebCLPlatform;


[scriptable, uuid(8d1a0db2-94af-4333-9b55-9c516a1dbbea)]
interface IWebCL : nsISecurityCheckedComponent
{
  /**
   * Supported data types for kernel arguments.
   * This attribute lists the data type identifiers that are supported for
   * explicit kernel argument type conversions.
   * \see WebCL_types
   */
  [implicit_jscontext]
  readonly attribute nsIVariant types;

  /** The WebCL version information.
   * This attribute contains the WebCL version as an array of 4 integers.
   * Index 0 is major API version, 1 is minor API version, 2 is release number
   * and 4 is the source repository revision number of 0 if the value was not
   * available at build time.
   */
  [implicit_jscontext]
  readonly attribute nsIVariant version;

  // NOTE: Can't use IDL array (i.e. out count, [array size_is(count)] out retv)
  //       since it always requires the count out parameter to be given as object,
  //       even when it's not reallyused by the user.
  // NOTE: Can't use nsIArray since it doesn't provide an interface that is compatible
  //       with JS array.
  /** Get the list of available platforms.
   * \return Array of IWebCLPlatform instances as a JSArray wrapped in
   *  an nsIVariant.
   * \see clGetPlatformIDs
   */
  [implicit_jscontext]
  nsIVariant getPlatformIDs ();

  /** \see getPlatformIDs */
  [implicit_jscontext]
  nsIVariant getPlatforms ();

  /** Create a new WebCL context based on a list of devices.
   * \param aProperties Array of properties. Names are integers, values can be integers or objects.
   * \param aDevices Array of devices.
   * \return A new WebCLContext instance.
   * \see clCreateContext
   */
  [implicit_jscontext]
  IWebCLContext createContext (in nsIVariant aProperties, in nsIVariant aDevices);

  /** Create a new WebCL context. This function takes the type of devices to use.
   * \param aProperties Array of properties. Names are integers, values can be integers or objects.
   * \param aDeviceType The type of devices to use. All suitable devices available on the
   *  platform will be used.
   * \return A new WebCLContext instance.
   * \see clCreateContextFromType
   */
  [implicit_jscontext]
  IWebCLContext createContextFromType (in nsIVariant aProperties, in T_WebCLDeviceType aDeviceType);

  /** Wait for the commands identified by the listed events to complete.
   * The function will block the host thread untill finished.
   * \param aEventList Array of IWebCLEvents.
   * \see clWaitForEvents
   */
  [implicit_jscontext]
  void waitForEvents (in nsIVariant aEventList);

  /** Release the resources allocated by the OpenCL compiler.
   * \see clUnloadCompiler
   */
  [implicit_jscontext]
  void unloadCompiler ();

  // Prevent the following constants from leaking to C++ header - the same
  // identifiers are already available as defines from cl.h through wrapper.
  // NOTE: This will cause warning which can be safely ignored.
  // Sadly, doxygen gets confused and ignores the constants as well.
%{C++
  /*
%}
  const long CL_SUCCESS = 0;
  const long CL_DEVICE_NOT_FOUND = -1;
  const long CL_DEVICE_NOT_AVAILABLE = -2;
  const long CL_COMPILER_NOT_AVAILABLE = -3;
  const long CL_MEM_OBJECT_ALLOCATION_FAILURE = -4;
  const long CL_OUT_OF_RESOURCES = -5;
  const long CL_OUT_OF_HOST_MEMORY = -6;
  const long CL_PROFILING_INFO_NOT_AVAILABLE = -7;
  const long CL_MEM_COPY_OVERLAP = -8;
  const long CL_IMAGE_FORMAT_MISMATCH = -9;
  const long CL_IMAGE_FORMAT_NOT_SUPPORTED = -10;
  const long CL_BUILD_PROGRAM_FAILURE = -11;
  const long CL_MAP_FAILURE = -12;
  const long CL_MISALIGNED_SUB_BUFFER_OFFSET = -13;
  const long CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST = -14;
  const long CL_INVALID_VALUE = -30;
  const long CL_INVALID_DEVICE_TYPE = -31;
  const long CL_INVALID_PLATFORM = -32;
  const long CL_INVALID_DEVICE = -33;
  const long CL_INVALID_CONTEXT = -34;
  const long CL_INVALID_QUEUE_PROPERTIES = -35;
  const long CL_INVALID_COMMAND_QUEUE = -36;
  const long CL_INVALID_HOST_PTR = -37;
  const long CL_INVALID_MEM_OBJECT = -38;
  const long CL_INVALID_IMAGE_FORMAT_DESCRIPTOR = -39;
  const long CL_INVALID_IMAGE_SIZE = -40;
  const long CL_INVALID_SAMPLER = -41;
  const long CL_INVALID_BINARY = -42;
  const long CL_INVALID_BUILD_OPTIONS = -43;
  const long CL_INVALID_PROGRAM = -44;
  const long CL_INVALID_PROGRAM_EXECUTABLE = -45;
  const long CL_INVALID_KERNEL_NAME = -46;
  const long CL_INVALID_KERNEL_DEFINITION = -47;
  const long CL_INVALID_KERNEL = -48;
  const long CL_INVALID_ARG_INDEX = -49;
  const long CL_INVALID_ARG_VALUE = -50;
  const long CL_INVALID_ARG_SIZE = -51;
  const long CL_INVALID_KERNEL_ARGS = -52;
  const long CL_INVALID_WORK_DIMENSION = -53;
  const long CL_INVALID_WORK_GROUP_SIZE = -54;
  const long CL_INVALID_WORK_ITEM_SIZE = -55;
  const long CL_INVALID_GLOBAL_OFFSET = -56;
  const long CL_INVALID_EVENT_WAIT_LIST = -57;
  const long CL_INVALID_EVENT = -58;
  const long CL_INVALID_OPERATION = -59;
  const long CL_INVALID_GL_OBJECT = -60;
  const long CL_INVALID_BUFFER_SIZE = -61;
  const long CL_INVALID_MIP_LEVEL = -62;
  const long CL_INVALID_GLOBAL_WORK_SIZE = -63;
  const long CL_INVALID_PROPERTY = -64;
  const long CL_VERSION_1_0 = 1;
  const long CL_VERSION_1_1 = 1;
  const long CL_FALSE = 0;
  const long CL_TRUE = 1;
  const long CL_PLATFORM_PROFILE = 0x0900;
  const long CL_PLATFORM_VERSION = 0x0901;
  const long CL_PLATFORM_NAME = 0x0902;
  const long CL_PLATFORM_VENDOR = 0x0903;
  const long CL_PLATFORM_EXTENSIONS = 0x0904;
  const long CL_DEVICE_TYPE_DEFAULT = (1<<0);
  const long CL_DEVICE_TYPE_CPU = (1<<1);
  const long CL_DEVICE_TYPE_GPU = (1<<2);
  const long CL_DEVICE_TYPE_ACCELERATOR = (1<<3);
  const unsigned long CL_DEVICE_TYPE_ALL = 0xFFFFFFFF;
  const long CL_DEVICE_TYPE = 0x1000;
  const long CL_DEVICE_VENDOR_ID = 0x1001;
  const long CL_DEVICE_MAX_COMPUTE_UNITS = 0x1002;
  const long CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS = 0x1003;
  const long CL_DEVICE_MAX_WORK_GROUP_SIZE = 0x1004;
  const long CL_DEVICE_MAX_WORK_ITEM_SIZES = 0x1005;
  const long CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR = 0x1006;
  const long CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT = 0x1007;
  const long CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT = 0x1008;
  const long CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG = 0x1009;
  const long CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT = 0x100A;
  const long CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE = 0x100B;
  const long CL_DEVICE_MAX_CLOCK_FREQUENCY = 0x100C;
  const long CL_DEVICE_ADDRESS_BITS = 0x100D;
  const long CL_DEVICE_MAX_READ_IMAGE_ARGS = 0x100E;
  const long CL_DEVICE_MAX_WRITE_IMAGE_ARGS = 0x100F;
  const long CL_DEVICE_MAX_MEM_ALLOC_SIZE = 0x1010;
  const long CL_DEVICE_IMAGE2D_MAX_WIDTH = 0x1011;
  const long CL_DEVICE_IMAGE2D_MAX_HEIGHT = 0x1012;
  const long CL_DEVICE_IMAGE3D_MAX_WIDTH = 0x1013;
  const long CL_DEVICE_IMAGE3D_MAX_HEIGHT = 0x1014;
  const long CL_DEVICE_IMAGE3D_MAX_DEPTH = 0x1015;
  const long CL_DEVICE_IMAGE_SUPPORT = 0x1016;
  const long CL_DEVICE_MAX_PARAMETER_SIZE = 0x1017;
  const long CL_DEVICE_MAX_SAMPLERS = 0x1018;
  const long CL_DEVICE_MEM_BASE_ADDR_ALIGN = 0x1019;
  const long CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE = 0x101A;
  const long CL_DEVICE_SINGLE_FP_CONFIG = 0x101B;
  const long CL_DEVICE_GLOBAL_MEM_CACHE_TYPE = 0x101C;
  const long CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE = 0x101D;
  const long CL_DEVICE_GLOBAL_MEM_CACHE_SIZE = 0x101E;
  const long CL_DEVICE_GLOBAL_MEM_SIZE = 0x101F;
  const long CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE = 0x1020;
  const long CL_DEVICE_MAX_CONSTANT_ARGS = 0x1021;
  const long CL_DEVICE_LOCAL_MEM_TYPE = 0x1022;
  const long CL_DEVICE_LOCAL_MEM_SIZE = 0x1023;
  const long CL_DEVICE_ERROR_CORRECTION_SUPPORT = 0x1024;
  const long CL_DEVICE_PROFILING_TIMER_RESOLUTION = 0x1025;
  const long CL_DEVICE_ENDIAN_LITTLE = 0x1026;
  const long CL_DEVICE_AVAILABLE = 0x1027;
  const long CL_DEVICE_COMPILER_AVAILABLE = 0x1028;
  const long CL_DEVICE_EXECUTION_CAPABILITIES = 0x1029;
  const long CL_DEVICE_QUEUE_PROPERTIES = 0x102A;
  const long CL_DEVICE_NAME = 0x102B;
  const long CL_DEVICE_VENDOR = 0x102C;
  const long CL_DRIVER_VERSION = 0x102D;
  const long CL_DEVICE_PROFILE = 0x102E;
  const long CL_DEVICE_VERSION = 0x102F;
  const long CL_DEVICE_EXTENSIONS = 0x1030;
  const long CL_DEVICE_PLATFORM = 0x1031;
  const long CL_DEVICE_DOUBLE_FP_CONFIG = 0x1032;
  const long CL_DEVICE_HALF_FP_CONFIG = 0x1033;
  const long CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF = 0x1034;
  const long CL_DEVICE_HOST_UNIFIED_MEMORY = 0x1035;
  const long CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR = 0x1036;
  const long CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT = 0x1037;
  const long CL_DEVICE_NATIVE_VECTOR_WIDTH_INT = 0x1038;
  const long CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG = 0x1039;
  const long CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT = 0x103A;
  const long CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE = 0x103B;
  const long CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF = 0x103C;
  const long CL_DEVICE_OPENCL_C_VERSION = 0x103D;
  const long CL_FP_DENORM = (1<<0);
  const long CL_FP_INF_NAN = (1<<1);
  const long CL_FP_ROUND_TO_NEAREST = (1<<2);
  const long CL_FP_ROUND_TO_ZERO = (1<<3);
  const long CL_FP_ROUND_TO_INF = (1<<4);
  const long CL_FP_FMA = (1<<5);
  const long CL_FP_SOFT_FLOAT = (1<<6);
  const long CL_NONE = 0x0;
  const long CL_READ_ONLY_CACHE = 0x1;
  const long CL_READ_WRITE_CACHE = 0x2;
  const long CL_LOCAL = 0x1;
  const long CL_GLOBAL = 0x2;
  const long CL_EXEC_KERNEL = (1<<0);
  const long CL_EXEC_NATIVE_KERNEL = (1<<1);
  const long CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE = (1<<0);
  const long CL_QUEUE_PROFILING_ENABLE = (1<<1);
  const long CL_CONTEXT_REFERENCE_COUNT = 0x1080;
  const long CL_CONTEXT_DEVICES = 0x1081;
  const long CL_CONTEXT_PROPERTIES = 0x1082;
  const long CL_CONTEXT_NUM_DEVICES = 0x1083;
  const long CL_CONTEXT_PLATFORM = 0x1084;
  const long CL_QUEUE_CONTEXT = 0x1090;
  const long CL_QUEUE_DEVICE = 0x1091;
  const long CL_QUEUE_REFERENCE_COUNT = 0x1092;
  const long CL_QUEUE_PROPERTIES = 0x1093;
  const long CL_MEM_READ_WRITE = (1<<0);
  const long CL_MEM_WRITE_ONLY = (1<<1);
  const long CL_MEM_READ_ONLY = (1<<2);
  const long CL_MEM_USE_HOST_PTR = (1<<3);
  const long CL_MEM_ALLOC_HOST_PTR = (1<<4);
  const long CL_MEM_COPY_HOST_PTR = (1<<5);
  const long CL_R = 0x10B0;
  const long CL_A = 0x10B1;
  const long CL_RG = 0x10B2;
  const long CL_RA = 0x10B3;
  const long CL_RGB = 0x10B4;
  const long CL_RGBA = 0x10B5;
  const long CL_BGRA = 0x10B6;
  const long CL_ARGB = 0x10B7;
  const long CL_INTENSITY = 0x10B8;
  const long CL_LUMINANCE = 0x10B9;
  const long CL_Rx = 0x10BA;
  const long CL_RGx = 0x10BB;
  const long CL_RGBx = 0x10BC;
  const long CL_SNORM_INT8 = 0x10D0;
  const long CL_SNORM_INT16 = 0x10D1;
  const long CL_UNORM_INT8 = 0x10D2;
  const long CL_UNORM_INT16 = 0x10D3;
  const long CL_UNORM_SHORT_565 = 0x10D4;
  const long CL_UNORM_SHORT_555 = 0x10D5;
  const long CL_UNORM_INT_101010 = 0x10D6;
  const long CL_SIGNED_INT8 = 0x10D7;
  const long CL_SIGNED_INT16 = 0x10D8;
  const long CL_SIGNED_INT32 = 0x10D9;
  const long CL_UNSIGNED_INT8 = 0x10DA;
  const long CL_UNSIGNED_INT16 = 0x10DB;
  const long CL_UNSIGNED_INT32 = 0x10DC;
  const long CL_HALF_FLOAT = 0x10DD;
  const long CL_FLOAT = 0x10DE;
  const long CL_MEM_OBJECT_BUFFER = 0x10F0;
  const long CL_MEM_OBJECT_IMAGE2D = 0x10F1;
  const long CL_MEM_OBJECT_IMAGE3D = 0x10F2;
  const long CL_MEM_TYPE = 0x1100;
  const long CL_MEM_FLAGS = 0x1101;
  const long CL_MEM_SIZE = 0x1102;
  const long CL_MEM_HOST_PTR = 0x1103;
  const long CL_MEM_MAP_COUNT = 0x1104;
  const long CL_MEM_REFERENCE_COUNT = 0x1105;
  const long CL_MEM_CONTEXT = 0x1106;
  const long CL_MEM_ASSOCIATED_MEMOBJECT = 0x1107;
  const long CL_MEM_OFFSET = 0x1108;
  const long CL_IMAGE_FORMAT = 0x1110;
  const long CL_IMAGE_ELEMENT_SIZE = 0x1111;
  const long CL_IMAGE_ROW_PITCH = 0x1112;
  const long CL_IMAGE_SLICE_PITCH = 0x1113;
  const long CL_IMAGE_WIDTH = 0x1114;
  const long CL_IMAGE_HEIGHT = 0x1115;
  const long CL_IMAGE_DEPTH = 0x1116;
  const long CL_ADDRESS_NONE = 0x1130;
  const long CL_ADDRESS_CLAMP_TO_EDGE = 0x1131;
  const long CL_ADDRESS_CLAMP = 0x1132;
  const long CL_ADDRESS_REPEAT = 0x1133;
  const long CL_ADDRESS_MIRRORED_REPEAT = 0x1134;
  const long CL_FILTER_NEAREST = 0x1140;
  const long CL_FILTER_LINEAR = 0x1141;
  const long CL_SAMPLER_REFERENCE_COUNT = 0x1150;
  const long CL_SAMPLER_CONTEXT = 0x1151;
  const long CL_SAMPLER_NORMALIZED_COORDS = 0x1152;
  const long CL_SAMPLER_ADDRESSING_MODE = 0x1153;
  const long CL_SAMPLER_FILTER_MODE = 0x1154;
  const long CL_MAP_READ = (1<<0);
  const long CL_MAP_WRITE = (1<<1);
  const long CL_PROGRAM_REFERENCE_COUNT = 0x1160;
  const long CL_PROGRAM_CONTEXT = 0x1161;
  const long CL_PROGRAM_NUM_DEVICES = 0x1162;
  const long CL_PROGRAM_DEVICES = 0x1163;
  const long CL_PROGRAM_SOURCE = 0x1164;
  const long CL_PROGRAM_BINARY_SIZES = 0x1165;
  const long CL_PROGRAM_BINARIES = 0x1166;
  const long CL_PROGRAM_BUILD_STATUS = 0x1181;
  const long CL_PROGRAM_BUILD_OPTIONS = 0x1182;
  const long CL_PROGRAM_BUILD_LOG = 0x1183;
  const long CL_BUILD_SUCCESS = 0;
  const long CL_BUILD_NONE = -1;
  const long CL_BUILD_ERROR = -2;
  const long CL_BUILD_IN_PROGRESS = -3;
  const long CL_KERNEL_FUNCTION_NAME = 0x1190;
  const long CL_KERNEL_NUM_ARGS = 0x1191;
  const long CL_KERNEL_REFERENCE_COUNT = 0x1192;
  const long CL_KERNEL_CONTEXT = 0x1193;
  const long CL_KERNEL_PROGRAM = 0x1194;
  const long CL_KERNEL_WORK_GROUP_SIZE = 0x11B0;
  const long CL_KERNEL_COMPILE_WORK_GROUP_SIZE = 0x11B1;
  const long CL_KERNEL_LOCAL_MEM_SIZE = 0x11B2;
  const long CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE = 0x11B3;
  const long CL_KERNEL_PRIVATE_MEM_SIZE = 0x11B4;
  const long CL_EVENT_COMMAND_QUEUE = 0x11D0;
  const long CL_EVENT_COMMAND_TYPE = 0x11D1;
  const long CL_EVENT_REFERENCE_COUNT = 0x11D2;
  const long CL_EVENT_COMMAND_EXECUTION_STATUS = 0x11D3;
  const long CL_EVENT_CONTEXT = 0x11D4;
  const long CL_COMMAND_NDRANGE_KERNEL = 0x11F0;
  const long CL_COMMAND_TASK = 0x11F1;
  const long CL_COMMAND_NATIVE_KERNEL = 0x11F2;
  const long CL_COMMAND_READ_BUFFER = 0x11F3;
  const long CL_COMMAND_WRITE_BUFFER = 0x11F4;
  const long CL_COMMAND_COPY_BUFFER = 0x11F5;
  const long CL_COMMAND_READ_IMAGE = 0x11F6;
  const long CL_COMMAND_WRITE_IMAGE = 0x11F7;
  const long CL_COMMAND_COPY_IMAGE = 0x11F8;
  const long CL_COMMAND_COPY_IMAGE_TO_BUFFER = 0x11F9;
  const long CL_COMMAND_COPY_BUFFER_TO_IMAGE = 0x11FA;
  const long CL_COMMAND_MAP_BUFFER = 0x11FB;
  const long CL_COMMAND_MAP_IMAGE = 0x11FC;
  const long CL_COMMAND_UNMAP_MEM_OBJECT = 0x11FD;
  const long CL_COMMAND_MARKER = 0x11FE;
  const long CL_COMMAND_ACQUIRE_GL_OBJECTS = 0x11FF;
  const long CL_COMMAND_RELEASE_GL_OBJECTS = 0x1200;
  const long CL_COMMAND_READ_BUFFER_RECT = 0x1201;
  const long CL_COMMAND_WRITE_BUFFER_RECT = 0x1202;
  const long CL_COMMAND_COPY_BUFFER_RECT = 0x1203;
  const long CL_COMMAND_USER = 0x1204;
  const long CL_COMPLETE = 0x0;
  const long CL_RUNNING = 0x1;
  const long CL_SUBMITTED = 0x2;
  const long CL_QUEUED = 0x3;
  const long CL_BUFFER_CREATE_TYPE_REGION = 0x1220;
  const long CL_PROFILING_COMMAND_QUEUED = 0x1280;
  const long CL_PROFILING_COMMAND_SUBMIT = 0x1281;
  const long CL_PROFILING_COMMAND_START = 0x1282;
  const long CL_PROFILING_COMMAND_END = 0x1283;
%{C++
  */
%}

};

